home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / jcool01.zip / EX4_9.C < prev    next >
C/C++ Source or Header  |  1992-08-24  |  1KB  |  29 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12. // Updated: JAM 08/21/92 -- made j long and output it (so loop not optimized)
  13.  
  14. #include <iostream.h>
  15.  
  16. #include <cool/Timer.h>                // Includer COOL timer class
  17.  
  18. int main (void) {
  19.   CoolTimer t1;                    // Create a CoolTimer object
  20.   volatile long sum = 0;     // use in loop to discourage optimizations
  21.   t1.mark ();                    // Set start reference point
  22.   for (long i = 0; i < 1000000L; i++)    // Loop for 1000000 times and
  23.     sum = sum + i;                    // Sum up numbers
  24.   long elapsed = t1.real();
  25.   cout << "Summation of integers from 0 through 1000000 (" << sum << ") took ";
  26.   cout << elapsed << " milliseconds\n";    // Output time since mark
  27.   return 0;                    // Return valid competion code
  28. }
  29.